# from concurrent.futures import ThreadPoolExecutor
# from concurrent.futures import ProcessPoolExecutor
# import time
# def task(arg):
#     print(arg)
#     time.sleep(1)
#
# # pool = ProcessPoolExecutor(5)
# pool = ThreadPoolExecutor(5)
#
# for i in range(50):
#     pool.submit(task,i)

"""
import json
from datetime import date
from datetime import datetime


class JsonCustomEncoder(json.JSONEncoder):
    def default(self, field):
        if isinstance(field, datetime):
            return field.strftime('%Y-%m-%d %H')
        elif isinstance(field, date):
            return field.strftime('%Y-%m-%d')
        elif isinstance(field, Response):
            return field.__dict__
        else:
            return json.JSONEncoder.default(self, field)

class Response(object):
    def __init__(self):
        self.status =True
        self.data = "asdf"
data = {
    'k1': 123,
    'k2': datetime.now(),
    'k3': Response()
}
ds = json.dumps(data, cls=JsonCustomEncoder)
print(ds)
"""

import requests
import hashlib
import time

current_time = time.time()
app_id = '12sadsdsdsdsdsfsdfdsfdsf'
app_id_time = '{}|{}'.format(app_id,current_time)
m = hashlib.md5()
m.update(app_id_time.encode('utf-8'))
auth_key = m.hexdigest()
auth_key_time = '{}|{}'.format(auth_key,current_time)
print(auth_key_time)

host_data = {
    'status':True,
    'data':{
        'hostname':'c1.com',
        'disk':{'status':True,'data':'xxx'},
        'mem':{'status':True,'data':'xxx'},
        'nic':{'status':True,'data':'xxx'},
        }
    }
"""get传参两种方式,?和params"""
# requests.get(url='http://127.0.0.1:8000/api/asset?k1=21&k2=v1')
# requests.get(url='http://127.0.0.1:8000/api/asset',params=host_data)
"""post传参，data和json,params"""
# requests.post(url='http://127.0.0.1:8000/api/asset',headers={'a':'1213'},params={'k1':'v1','k2':'v2'},data={'username':'zhang','pwd':123})
# requests.post(url='http://127.0.0.1:8000/api/asset',data=host_data)
response = requests.post(url='http://127.0.0.1:8000/api/asset',
              json=host_data,
              headers={'authkey':auth_key_time},
              )  #字典里面套字典用json
print(response.text)